<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>活动抽奖</title>
<!-- InstanceEndEditable -->

<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<link href="../css/validator3.css" type="text/css" rel="stylesheet" />
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/scrollTop.js"></script> 

<script type="text/javascript">
	var pageIndex=1;
	var pageCount=0;
	var _swpId;
	$(function(){
		findSweepstakesList();
	})

	function findSweepstakesList(){
		$.ajax({
			url:'../sweepstakes/find/sweepstakesList/'+pageIndex+'/10',
			datatype:'json',
			data:{"prizeTypeId":2},
			type:'get',
			success:
				function(data){
				var obj = DealAndShowMsg(data,false,true);
				var rst= JSON.parse(data);
				
					if(rst.result.len>0){
					loadtable(rst)
					 var shu = rst.result.len;
					 pagecount = Math.ceil(shu/10);
					 $("#pager").pager({ pagenumber:pageIndex, pagecount: pagecount, buttonClickCallback: PageClick });
					}
				
			}
		})
	}
	
	function openAward(swpId,p){
		$("#sweepContent").empty();
		$("#div1 ul").empty()

		$.ajax({
			url:'../prizelevel/find/prizelv/'+swpId,
			datatype:'json',
			type:'get',
			success:
				function(data){
				var rst= JSON.parse(data);
				if(IsEmpty(rst)){
					art.dialog({fixed:true, lock: true,content:"数据查询错误",icon:'error',ok:true});	
					return false;
					}
					if(rst.state==0){
						if(rst.result.len>0){
							loadPrizeLevelDetail(rst,swpId)
							$("#sweepContent").html(p.parents("li").find("p").html())
							$("#tocj").attr("onclick","cj("+swpId+")");
							_swpId=swpId;
							}
						 }else if(rst.state==1){
								art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
					}else{
						checkStateShowErrorMsgAndDealResult(data);
					}	
				
			}
		})
		$.ajax({
			url:'../sweepstakes/update/particNumsCount/'+swpId,
			datatype:'json',
			type:'get',
			success:
				function(data){
				var rst= JSON.parse(data);
				if(rst.state==0){
		$("#partNum2").html("参与人数："+rst.msg)					
				}else{
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}
			}
		})
		
		
		
			
		$("#yinying1,#windowPop").show();
		ScrollTop("div1");
	}
	
	function safe(){
		$.ajax({
			url:'../sweepstakes/update/sweepstackesStatus/'+_swpId,
			datatype:'json',
			type:'get',
			success:
				function(data){
				var rst= JSON.parse(data);
				if(IsEmpty(rst)){
					art.dialog({fixed:true, lock: true,content:"修改错误",icon:'error',ok:true});	
					return false;
					}
					if(rst.state==0){
						window.location.reload();
						 }else if(rst.state==1){
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
					}else{
						checkStateShowErrorMsgAndDealResult(data);
					}	
				
			}
		})
	}
	
	
	function loadPrizeLevelDetail(rst,swpId){
		var params = new Array("prizelvName", "PrizeName","winnersNum");// "PayCash", "PayPos", "PayDepstAmt", "PayCheck", "PayPersonCard", "PayIntAmtMny", "StaName", "PaidName"
		var phArray = new Array();
		var count=0;
		if (params != null) {
			$(params).each(function(pIndex, pData) {
				$.each(rst.result.head, function(hIndex, hData) {
					if (pData == hData) {
						phArray[count++] = hIndex;
					}
				});
			});
		}		
				$("#prizeLevelDetail").empty();
			for ( var i = 0; i < rst.result.data.length; i++) {
				 var htm="<p>"; 
				htm+=getHtmlString(getHeadIndexValue(i, rst, "prizelvName"))+":"
				htm+="奖品数量："+getHtmlInt(getHeadIndexValue(i, rst, "winnersNum"))+","
				htm+=getHtmlString(getHeadIndexValue(i, rst, "PrizeName"))
				htm+="</p>";
				$("#prizeLevelDetail").append(htm)
				var htm2="<input  class=\"btn\" type=\"button\" onclick=\"cj("+swpId+","+getHtmlInt(getHeadIndexValue(i, rst, "prizeLvId"))+")\" value=\""+getHtmlString(getHeadIndexValue(i, rst, "prizelvName"))+"抽奖\">"
				
				$("#div_cj").prepend(htm2)
			}
	}
	PageClick = function(pageclickednumber) {
		pageIndex=pageclickednumber;
		findSweepstakesList();
	}
	function cj(swpId,plvId){
		$.ajax({
			url:'../prize/update/onelottery/'+swpId+'/'+plvId,
			datatype:'json',
			type:'get',
			success:
				function(data){
				var rst=JSON.parse(data);
				if(IsEmpty(rst)){
					art.dialog({fixed:true, lock: true,content:"修改错误",icon:'error',ok:true});	
					return false;
					}
					if(rst.state==0){
						loadAwardtable(rst,"div1")
						 }else if(rst.state==1){
								art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
					}else{
						checkStateShowErrorMsgAndDealResult(data);
					}	
				
			}
		})
	}
	
	
	
	function	loadAwardtable(rst,divId){
		var params = new Array("CusName", "Mp","Pname","CreateTime");// "PayCash", "PayPos", "PayDepstAmt", "PayCheck", "PayPersonCard", "PayIntAmtMny", "StaName", "PaidName"
		var phArray = new Array();
		var count=0;
		if (params != null) {
			$(params).each(function(pIndex, pData) {
				$.each(rst.result.head, function(hIndex, hData) {
					if (pData == hData) {
						phArray[count++] = hIndex;
					}
				});
			});
		}
		
		
				$("#"+divId+" ul").empty();
			for ( var i = 0; i < rst.result.data.length; i++) {	
				 var htm="<li>";
				var d=rst.result.data[i]
		
				for ( var j = 0; j < phArray.length; j++) {
					if(j==1){
						htm+="<i>电话：</i>";
						htm+= getReplaceStr(d[phArray[j]],3,7,"****"); 

					}else{
						
				htm+=d[phArray[j]]
					}
				}
				htm+="</li>";
				$("#"+divId+" ul").append(htm)
			}
			ScrollTop("div1");

	}

	
	function loadtable(rst){
		var params = new Array("swptaksName", "swptaksContent","swptaksBeginDate","staName","status","swptaksID","prizeTypeId");// "PayCash", "PayPos", "PayDepstAmt", "PayCheck", "PayPersonCard", "PayIntAmtMny", "StaName", "PaidName"
		var phArray = new Array();
		var count=0;
		if (params != null) {
			$(params).each(function(pIndex, pData) {
				$.each(rst.result.head, function(hIndex, hData) {
					if (pData == hData) {
						phArray[count++] = hIndex;
					}
				});
			});
		}
		
				$("#rewardList").empty();
			for ( var i = 0; i < rst.result.data.length; i++) {
				 var htm="<li>";
				var d=rst.result.data[i]
				
				htm+="<strong>"+getHeadIndexValue(i, rst, "swptaksName")+"</strong>"
				htm+="<p>"+getHeadIndexValue(i, rst, "swptaksContent")+"</p>";
				htm+= "<b>"+getHeadIndexValue(i, rst, "swptaksBeginDate")+"</b>"
				htm+= "<span>"+ getHeadIndexValue(i, rst, "staName") +"</span>"
				var state=getHeadIndexValue(i, rst, "status")
				var cancj=getHeadIndexValue(i, rst, "cancj");
				if(state==0){
					if(cancj==0){
						
					htm+="<i><input class=\"common_btn newAward\" type=\"button\" value=\"开奖\" onclick=\"openAward("+getHeadIndexValue(i, rst, "swptaksID")+",$(this) )\" ></i>"	
					}else{
					htm+="<i><input class=\"common_btn newAward\" type=\"button\" value=\"未到开奖時間\"  ></i>"	
					
					}
					
				}else if(state==1){
					htm+="<i><input class=\"common_btn newAward\" type=\"button\" value=\"开奖中\" onclick=\"openAward("+getHeadIndexValue(i, rst, "swptaksID")+",$(this) )\" ></i>"	

				}else if(state==2){
					htm+="<i><input class=\"common_btn\" type=\"button\" value=\"查询获奖名单\" onclick=\"showAward("+getHeadIndexValue(i, rst, "swptaksID")+")\"></i>"

				}	
				htm+="</li>";
				$("#rewardList").append(htm)
			}

	}
	
	function showAward(swpId) {
		
		$.ajax({
			type : "get",
			async:false,
			data:'swptaksId='+swpId,
			datatype : "json",
			url : "../winner/find/winnerList",
			success : function(data) {
				var rst = JSON.parse(data);
						if(rst.state==0){
							if(rst.result.len > 0){
								$("#partNum1").html("参加人数："+getHeadIndexValue(0, rst, "particNums"))

								loadAwardtable(rst,"div2");
								$("#yinying1,#windowPop2").show();
								ScrollTop("div2");
								addMargin($("#windowPop2"));

						}else{
							art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
										}
			
						}
			}	
		});
		
			
		
	}

</script>


</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 
<script type="text/javascript">
$(function(){
	Hover($("#rewardList"));
	$("#closeThe,#esc").click(function(){
		window.location.reload()
		$("#windowPop,#yinying1").hide();
		$("#windowPop2,#yinying1").hide();

	})
	$("#rewardList i").children(":button").click(function(){
		$("#yinying1,#windowPop").show();
		ScrollTop();
	})
	addMargin($("#windowPop"));
})
</script>
<div id="windowPop2" class="hideDiv">
  <div class="closeTop"><span id="closeThe"><img src="../images/close.png"></span></div>
  <div class="boxcontent box_blue">
    <div class="box_activities">
      <div class="title"><span>中奖公告：</span><i id="partNum1"></i></div>
      <div class="Detail" id="div2">
        <ul class="rewardPeople">
         </ul>
        
      </div>
    </div>
  </div>
</div>

<div id="windowPop" class="hideDiv">
  <div class="closeTop"><span id="closeThe"><img src="../images/close.png"></span></div>
  <div class="boxcontent">
    <div class="box_activities">
      <div class="title"><span>奖项设置：</span></div>
      <div class="Detail" id="prizeLevelDetail">
      </div>
    </div>
  </div>
  <div class="boxcontent">
    <div class="box_activities">
      <div class="title"><span>活动说明：</span></div>
      <div class="Detail" id="sweepContent">
        <p>本次活动每人可以参加3次 </p>
        <p>我们的中奖率高达33.3%！！</p>
      </div>
    </div>
  </div>
  <div class="bottomBtn" id="div_cj">
    <input type="button" class="safe common_btn" id="safe" value="保存信息" onclick="safe()">
    <input type="button" id="esc" class="esc common_btn" value="取消">
  </div>
  <div class="boxcontent box_blue">
    <div class="box_activities">
      <div class="title"><span>中奖公告：</span><i id="partNum2"></i></div>
      <div class="Detail" id="div1">
        <ul class="rewardPeople">
       
        </ul>
      </div>
    </div>
   
  </div>
</div>
<div id="yinying1"></div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">活动抽奖</div>
    <div class="rewardTitle"><b class="name">活动名称</b><b class="det">活动简介</b><b class="date">开奖日期</b><b class="state">状态</b><b class="set">操作</b></div>
    <ul class="rewardList" id="rewardList">
      
    </ul>
    <div id="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
showTab(3,2);
</script>
</body>
<!-- InstanceEnd -->
</html>
